<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>邮件服务</title>
    <header th:replace="header::html"></header>
</head>
<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">邮件</a>
        <a>
          <cite>邮件服务</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>
<div class="x-body">
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <form class="layui-form">
                            <input type="hidden" id="mailId" th:value="${sysMail.id}" name="id">
                            <div class="layui-form-item">
                                <label for="L_host" class="layui-form-label">
                                    <span class="x-red">*</span>主机
                                </label>
                                <div class="layui-input-inline">
                                    <input type="text" id="L_host" name="host" required="" th:value="${sysMail.host}"
                                           autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">
                                    邮件服务器主机host，目前只支持SMTP协议(可以是163或者qq)
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label for="L_port" class="layui-form-label">
                                    <span class="x-red">*</span>端口
                                </label>
                                <div class="layui-input-inline">
                                    <input type="number" id="L_port" name="port" required="" th:value="${sysMail.port}"
                                           autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">
                                    邮件服务器端口，默认：465
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label for="L_username" class="layui-form-label">
                                    <span class="x-red">*</span>登录账号
                                </label>
                                <div class="layui-input-inline">
                                    <input type="text" id="L_username" name="username" required=""
                                           th:value="${sysMail.username}" lay-verify="username" autocomplete="off"
                                           class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">
                                    登录邮件服务器的账号，例如username@163.com
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label for="L_password" class="layui-form-label">
                                    <span class="x-red">*</span>登录密码
                                </label>
                                <div class="layui-input-inline">
                                    <input type="password" id="L_password" name="password" required=""
                                           th:value="${sysMail.password}" lay-verify="password" autocomplete="off"
                                           class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">
                                    登录邮件服务器的密码，该密码通常是通过短信动态授权第三方登录的密码
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label for="L_nickname" class="layui-form-label">
                                    <span class="x-red">*</span>发送昵称
                                </label>
                                <div class="layui-input-inline">
                                    <input type="text" id="L_nickname" name="nickname" required="" autocomplete="off"
                                           th:value="${sysMail.nickname}" class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">
                                    邮件服务器发送昵称，默认：柠檬水
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label for="L_protocol" class="layui-form-label">
                                    <span class="x-red">*</span>发送协议
                                </label>
                                <div class="layui-input-inline">
                                    <input type="text" id="L_protocol" name="protocol" required="" autocomplete="off"
                                           th:value="${sysMail.protocol}" class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">
                                    邮件服务器发送协议，默认：smtp
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label for="L_encoding" class="layui-form-label">
                                    <span class="x-red">*</span>字符集编码
                                </label>
                                <div class="layui-input-inline">
                                    <input type="text" id="L_encoding" name="encoding" required="" autocomplete="off"
                                           th:value="${sysMail.encoding}" class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">
                                    邮件服务器字符集编码，默认：UTF-8
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label for="L_timeout" class="layui-form-label">
                                    <span class="x-red">*</span>超时(毫秒)
                                </label>
                                <div class="layui-input-inline">
                                    <input type="number" id="L_timeout" name="timeout" required="" autocomplete="off"
                                           th:value="${sysMail.timeout}" class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">
                                    使用账号密码登录邮件服务器连接超时(毫秒),默认：25000
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label for="add" class="layui-form-label"></label>
                                <button class="layui-btn layui-btn-danger" id="add" lay-filter="add" lay-submit="">
                                    <i class="iconfont">&#xe6ad;</i>提交
                                </button>
                                <button class="layui-btn" type="reset"><i class="layui-icon">&#xe621;</i>重置</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer;

        //自定义验证规则
        form.verify({
            username: [/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/, '邮箱格式不正确，请输入有效的邮件账号！']
        });

        //监听提交
        form.on('submit(add)', function (data) {
            $.ajax({
                url: "/mail/saveOrUpdate",
                type: "POST",
                data: data.field,
                dataType: 'json',
                success: function (result) {
                    if (result.code != 200) {
                        layer.alert(result.msg);
                    } else {
                        layer.alert("设置成功", {icon: 6}, function (index) {
                            location.reload();
                        });
                    }
                }
            });
            return false;
        });
    });
</script>
</body>
</html>